// Google Chrome Game Tools
// Copyright (c) 2010 Joseph Huckaby

Class.create( 'Sprite', {
	
	id: '',
	x: 0,
	y: 0,
	width: 0,
	height: 0,
	opacity: 1.0,
	className: '',
	html: '',
	plane: null,
	destroyed: false,
	
	init: function() {
		if (!this.id) this.id = get_unique_id();
		
		var div = $(document.createElement('div'));
		div.id = this.id;
		div.className = this.className || '';
		var sty = div.style;
		sty.position = 'absolute';
		
		sty.left = '' + this.x + 'px';
		sty.top = '' + this.y + 'px';
		sty.width = '' + this.width + 'px';
		sty.height = '' + this.height + 'px';
		sty.opacity = (this.opacity == 1.0) ? '' : this.opacity;
		div.innerHTML = this.html || '';
		
		this.plane.div.appendChild( div );
		
		this.div = div;
		this.style = sty;
	},
	
	destroy: function() {
		if (!this.destroyed) {
			this.destroyed = true;
			this.plane.div.removeChild( this.div );
			delete this.plane.sprites[ this.id ];
			delete this.div;
			delete this.style;
		}
	},
	
	rename: function(new_id) {
		// give sprite a new id
		delete this.plane.sprites[this.id];
		this.plane.sprites[new_id] = this;
		this.id = new_id;
		this.div.id = this.id;
	},
	
	logic: function() {
		
	},
	
	draw: function() {
		// update position on screen
		this.style.left = '' + this.x + 'px';
		this.style.top = '' + this.y + 'px';
	}
	
} );
